<script type="text/javascript">
<!--

var items_nbgroup;

function getUrlForAction(action)
{
	return <?php echo '"'
. $this->url(array('controller' => 'browserajax',
//				   'project' => $this->project->name,
				   'action' => '"+action+"'),
			 'default', true, false)
. '?project=' . addslashes($this->project->name)
. '&"' ?>;

}

function register_position()
{
	mouse_x = 0;
	mouse_y = 0;
	document.onmousemove = position;
}

function position(evt){
	if(!evt)
		evt = window.event;
	mouse_x = evt.clientX;
	mouse_y = evt.clientY;
}

function cancel()
{
	document.getElementById('bulle').style.visibility = 'hidden';
}

function get_groupe()
{
	var groupe = "";
	for (i = 0; i < items_nbgroup; i++)
	{
		var grp = document.getElementById('Lb'+i).innerHTML;
		groupe += grp + ",";
	}
	return groupe;
}

function get_groupe_text()
{
	var text = "";
	for (i = 0; i < items_nbgroup; i++)
	{
		var grp = document.getElementById('Lb' + i).innerHTML;
		text += document.getElementById('checkRead' + grp).checked + "," + document.getElementById('checkWrite' + grp).checked + "," + document.getElementById('recursive' + grp).checked + ",";
	}
	return text;
}

function get_ajax(index)
{
    var xhr=null;
    if (window.XMLHttpRequest)
        xhr = new XMLHttpRequest();
    else if (window.ActiveXObject)
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    xhr.onreadystatechange = function() { alert_ajax(xhr, index); };
	return xhr;
}

function dumpRights(file)
{
	file = encodeURIComponent(file);
	var groupe = get_groupe();
	var xhr = get_ajax(1);
	xhr.open("GET", getUrlForAction("dump-rights")
		+ "name=" + file
		+ "&group=" + groupe.substring(0, groupe.length - 1), true);
	xhr.send(null);
}

function updateOrInsertRights(file)
{
	file = encodeURIComponent(file);
	var groupe = get_groupe();
	var xhr = get_ajax(2);
	var text = get_groupe_text();
	xhr.open("GET", getUrlForAction("update-or-insert-rights")
		+ "name=" + file
		+ "&rights=" + text.substring(0, text.length - 1)
		+ "&group=" + groupe.substring(0, groupe.length - 1), true);
	xhr.send(null);
}

function getListFile(file)
{
	file = encodeURIComponent(file);
	var xhr = get_ajax(3);
	xhr.open("GET", getUrlForAction("get-list-file")+"name="+file, true);
	xhr.send(null);
}

function fctWrite(group)
{
	if (document.getElementById('checkWrite'+group).checked == true)
		document.getElementById('checkRead'+group).checked = true;
}

function fctRead(group)
{
	if (document.getElementById('checkWrite'+group).checked == true)
		document.getElementById('checkRead'+group).checked = true;
}

function alert_ajax(xhr, index)
{
	var docXML = xhr.responseXML;
	if (docXML)
	{
		if (index == 1)
		{
			var items_groups = docXML.getElementsByTagName("groups").item(0).firstChild.data;
			items_nbgroup = docXML.getElementsByTagName("nbgroup").item(0).firstChild.data;
			if (docXML.getElementsByTagName("basename").item(0).firstChild) {
				basename = docXML.getElementsByTagName("basename").item(0).firstChild.data;
			} else {
				basename = "/";
			}
			var bulle = "<br /><h3>&nbsp;<?php echo T_('Acces rights for'); ?>" + " " + basename + "&nbsp;</h3>";
			bulle += items_groups;
			document.getElementById('bulle').style.visibility = 'visible';
			document.getElementById('bulle').innerHTML = bulle;
			document.getElementById('bulle').style.left = (mouse_x + 10) + "px";
  		document.getElementById('bulle').style.top = (mouse_y + 10) + "px";
		}
		if (index == 2)
		{
			var items_msg = docXML.getElementsByTagName("msg").item(0).firstChild.data;
			if (items_msg == "Ok")
				cancel();
			else
				document.getElementById('labelError').innerHTML = items_msg;
		}
		if (index == 3)
		{
      var txthtml2 = document.getElementById('txthtml2');
      var txthtml = docXML.getElementsByTagName("txthtml").item(0);
      txthtml2.innerHTML = txthtml.firstChild.data;
		}
	}
}
-->
</script>
<div class="usvn_info">
<h1><?php echo T_("Files list"); ?></h1>
</div>
<div class="usvn_info">
  <div id="txthtml2">
  </div>
</div>
<div id="bulle" class="bubblerights" align="center"></div>
<script type="text/javascript">
<!--
register_position();
getListFile('<?php echo $this->back ?>');
-->
</script>
